﻿using System.Collections.Generic;
using System.Diagnostics;
using Battle.Common;
using CardGameCore.Common;

namespace CardGameCore.Battle
{
    public class RoundPrepare : IRoundPrepare
    {
        private readonly IBattlefield _battlefield;
        private readonly IBattleSettings _battleSettings;
        private const int First = 0;
        
        public RoundPrepare(            
            IBattlefield battlefield,
            IBattleSettings battleSettings)
        {
            _battlefield = battlefield;
            _battleSettings = battleSettings;
        }

        public void Process()
        {
            ProcessHandCard(_battlefield.Player);
            ProcessHandCard(_battlefield.Enemy);
        }

        private void ProcessHandCard(Actor actor)
        {
            while (actor.HandCards.Count < _battleSettings.HandCardCount)
            {
                if (actor.CardPool.Count == 0)
                {
                    break;
                }

                var card = actor.CardPool[First];
                actor.HandCards.Add(card);
                actor.CardPool.RemoveAt(First);
            }
        }
    }
}